package com.example.demo.excelOperate;

import com.example.demo.valueObject.AntiCounterfeiting;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.stereotype.Component;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

@Component
public class FileInput {
    public List<AntiCounterfeiting> readExcel()
    {
        String dirPath = System.getProperty("user.dir");
        File file = new File(dirPath + "/"+"data.xlsx");
        List<AntiCounterfeiting> antiCounterfeitings = new ArrayList<>();
        try {
            InputStream is = new FileInputStream(file);
            antiCounterfeitings =  ExcelUtils.getCourseListByExcel(is);

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return antiCounterfeitings;
    }
    public void writeExcel(int rows)
    {
        String dirPath = System.getProperty("user.dir");
        File file = new File(dirPath + "/"+"data.xlsx");
        try {
            ExcelUtils.reviseTimes(file,rows);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
